--
-- 初始化.
--

local cjson = require("cjson.safe")
local cloak = require("src.cloak")

local fmt = string.format

--- 读取文件
-- @param path
--
local function read_file(path)
  local contents
  local file = io.open(path, "rb")
  if file then
    contents = file:read("*all")
    file:close()
  end
  return contents
end

--- 初始化
-- @param config_file_path
--
local function init(config_file_path)
  ngx.log(ngx.DEBUG, fmt("config_file_path: %s", config_file_path))

  -- 读取配置
  local contents = read_file(config_file_path)
  local config = cjson.decode(contents)

  cloak.init(config.user_agent_rules, config.ip_rules)
end

return {
  init = init
}